package student.action;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.struts2.ServletActionContext;


import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.util.DB;
import com.util.MyLog;

import edu.student.models.*;
/**
 * 
 * @author Sai Naga Sravani Peraka
 */
public class AdminHome extends ActionSupport{
	
	private Map<String, Object> session;
	private ArrayList<Lookup> allSemValues = new ArrayList<Lookup>();
	private ArrayList<String> semesterList = new ArrayList<String>();
	private ArrayList<Lookup> allCourseValues = new ArrayList<Lookup>();
	private ArrayList<String> courseList = new ArrayList<String>();
	private ArrayList<Lookup> semCourseList = new ArrayList<Lookup>();
	ArrayList<String> userList;	
	public ArrayList<String> getSemesterList() {
		return semesterList;
	}

	public void setSemesterList(ArrayList<String> semesterList) {
		this.semesterList = semesterList;
	}

	public ArrayList<String> getCourseList() {
		return courseList;
	}

	public void setCourseList(ArrayList<String> courseList) {
		this.courseList = courseList;
	}
	public ArrayList<Lookup> getSemCourseList() {
		return semCourseList;
	}

	public void setSemCourseList(ArrayList<Lookup> semCourseList) {
		this.semCourseList = semCourseList;
	}
	
	public ArrayList<String> getUserList() {
		return userList;
	}

	public void setUserList(ArrayList<String> userList) {
		this.userList = userList;
	}

	Lookup lookup =new Lookup();
	
	public String execute() throws Exception {
		session = ActionContext.getContext().getSession();
		String clicked = ServletActionContext.getRequest().getParameter("link");
		if(clicked.equals("lookups")){
			return "lookups";
		}
		else if(clicked.equals("course")){
			
			/*this.semCourseList = Lookup.findCourse("");
        	return "course";
			*/
			this.allSemValues=lookup.find("semester"," where is_current='y'");
			
			for (int i = 0; i < allSemValues.size(); i++){
	        	Lookup list = allSemValues.get(i);
	        	semesterList.add(list.getName());
	        	MyLog.log("semester name:"+list.getName());
	        }
			
			this.allCourseValues=lookup.find("subject"," where is_current='y'");
			for (int i = 0; i < allCourseValues.size(); i++){
	        	Lookup list = allCourseValues.get(i);
	        	courseList.add(list.getName());
	        	MyLog.log("course name:"+list.getName());
	        }
			return "course";
		}
		else if(clicked.equals("syllabus")){
		// Priya's code	
			this.allCourseValues=lookup.find("subject"," where is_current='y'");
			for (int i = 0; i < allCourseValues.size(); i++){
	        	Lookup list = allCourseValues.get(i);
	        	courseList.add(list.getName());
	        	MyLog.log("course name:"+list.getName());
	        }
			return "syllabus";

		
		}
		else if(clicked.equals("grades")){
			courseList=Enrollment.getSubjectList();
			semesterList=Enrollment.getSemesterList();
			userList=User.userListDetails("");
			return "grades";
		}
		else if(clicked.equals("registerUser")){
		return "registerUser";
		}
		return "error";
	}
}